@include('admin::layouts.header')
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>备份数据文件列表</legend>
    </fieldset>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
@include('admin::layouts.footer')
<script type="text/html" id="size">
    @{{d.sortSize}}
</script>
<script type="text/html" id="action">
    <a href="{{route('admin.data_base.down_file')}}?name=@{{d.name}}" class="layui-btn layui-btn-xs">下载</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var tableIn = table.render({
			id: 'database',
            elem: '#list',
            url: "{{route('admin.data_base.restore_data')}}",
            method:'get',
			toolbar: '#topBtn',
			title:'模块配置',
            cols: [[
                {field:'name', align:'center',title: '文件名称', width:250}
                ,{field:'size',align:'center', title: '文件大小', width:200,sort:true,templet:'#size'}
                ,{field:'time', align:'center',title: '备份时间', width:200,sort:true}
                ,{width:160,title: '操作', align:'center', toolbar: '#action'}
            ]],
			parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
				  return res;
			}	
        });
		table.on('tool(list)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确认要删除该备份文件吗？', function (index) {
                    loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{{route('admin.data_base.del_sql_files')}}",{_method:'DELETE',name:data.name},function(res){
						layer.close(loading);
                        if(res.status == 1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.error,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>
</body>
</html>